<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!-- START DEFAULT DATATABLE -->
<link rel="stylesheet" type="text/css" id="theme" href="/statics/css/theme-default.css"/>
<head>
<style>
    .panel-heading ul, .panel-heading ul li {
        float: left;
        list-style: none;
    }

    li .Wdate {
        height: 30px;
        width: 90px;
    }

    .panel-heading li {
        margin: 0 10px;
    }

    .panel-heading li, .panel-heading li select {
        height: 30px;
        line-height: 30px;
    }

</style>
</head>
<div class="panel panel-default">
    <div class="panel-heading row">
        <div class="col-sm-4">
            <h3 class="panel-title">餐厅菜单管理</h3>
        </div>
    </div>
    <div class="block">
        <form class="form-inline" role="form" action="/admin/queryMenus2.jspa" method="post">
            <div class="form-group">
                <%--<label class="sr-only">菜品名称</label>--%>
                菜品名称 &nbsp;<input type="text" id = "input1" class="form-control" name="itemName" placeholder="菜品名称" value="${itemName}"/>
            </div>
            &nbsp;&nbsp;&nbsp;
            <%--<div class="form-group">--%>

                    <%--&lt;%&ndash;<label class="sr-only">菜品类型</label>&ndash;%&gt;--%>
                        <%--<input type="button" value="食谱类型"/><input class="form-control" id = "input2" type="text" name="itemType" placeholder="食谱类型"/>--%>
            <%--</div>--%>
            食谱类型
            <div class="form-group">
                <label class="col-md-3 col-xs-12 control-label"></label>
                <%--<div class="col-md-6 col-xs-12">--%>

                    <select class="form-control select" name="itemType" id="sele1">

                        <c:if test="${itemType.equals('1')}">
                        <option value="1" selected>全部</option>
                        </c:if>
                        <c:if test="${!itemType.equals('1')}">
                            <option value="1">全部</option>
                        </c:if>
                        <c:forEach items="${menuService.findItemType()}" var ="root">

                            <c:if test="${itemType.equals(root)}">
                            <option value="${root}" selected>${root}</option>
                            </c:if>
                            <c:if test="${!itemType.equals(root)}">
                                <option value="${root}">${root}</option>
                            </c:if>
                        </c:forEach>
                    </select>
                <%--</div>--%>
            </div>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <button type="submit" class="btn btn-danger" id="button1">搜索</button>
        </form>
        <button id = "bus" class="btn btn-success" style="margin-left:90%;margin-bottom: 0px"><i class="fa fa-plus"></i></button>
    </div>
    <div class="panel-body">
            <table class="table">
                <thead>
                <tr>
                    <th>食谱分类</th>
                    <th>图片</th>
                    <th>名称</th>
                    <th>单位</th>
                    <th>描述</th>
                    <th>单价</th>
                    <th>虚拟库存</th>
                    <th>上下架&nbsp;&nbsp;(红:下架中 绿:上架中)</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id = "t1">
                <input type="hidden" id="hid1" value="${curs}"/>
                <c:if test="${menus.size()>0}">
                <c:forEach items="${menus}" var="root">
                    <tr class="item-comment comment-quote info" id="${root.menuId}">
                        <td>${root.itemType}</td>
                        <td><img src="/upload/${root.imageFile}" height="30px"></td>
                        <td>${root.itemName}</td>
                        <td>${root.itemUnit}</td>
                        <td>${root.itemDescription}</td>
                        <td>${root.itemPrice}</td>
                        <td><input value="${root.storeNum}" size="10px" style="text-align:center"/><input type="button" id="${root.menuId}" value="更改" onclick="updateStores(this)"/></td>
                        <script type="text/javascript">
                            function updateStores(sto){
                                var nm = $(sto).prev().prop("value");
                                var md = $(sto).prop("id");
                                if($(sto).prev().prop("value")>0){
                                    $.ajax({
                                        type:"post",
                                        url:"${pageContext.request.contextPath}/admin/storeUpdate.jspa",
                                        data:{menuId:md,nums:nm},
                                        success:function(){
                                            layer.open({content:"修改成功",time:3});
                                        }
                                    });
                                }else{
                                    layer.open({content:"库存数量不规范",time:1});
                                }
                            }
                        </script>
                            <%--上下架的图标--%>
                        <td>
                            <label class="switch">
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input  id = "${root.menuId}" type="checkbox" ${root.isUping=="1"?"checked":"" } value="0" onclick="ups(this)"/>
                                <span></span>
                            </label>
                        </td>
                        <td>
                            <button class="btn btn-info btn-rounded btn-sm" title="修改菜品" onclick="goEdit(this)"><span
                                    class="fa fa-pencil"></span></button>&nbsp;&nbsp;&nbsp;&nbsp;
                            <%--<button class="btn btn-success btn-rounded btnsm" title="上架" onclick="goUping(this)"><span--%>
                                    <%--class="fa fa-mail-forward"></span></button>--%>
                            <button class="btn btn-danger btn-rounded btn-sm" title="删除菜品" id="${root.menuId}" onClick="goCancel2(this)"><span
                                    class="fa fa-times"></span></button>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        <div class="panel-footer">
            <ul class="pagination pagination-sm pull-right">
                <c:if test="${curs}<=1">
                <li><a href="#">&laquo;</a></li>
                </c:if>
                <c:if test="${curs>1}">
                    <li><a href="/admin/queryMenus2.jspa?itemName=${itemName}&itemType=${itemType}&curpage=${curs-1}">&laquo;</a></li>
                </c:if>
                <c:forEach begin="1" end="${pa}" step="1" var="i">
                    <c:if test="${curs==i}">
                    <li class="active"><a href="/admin/queryMenus2.jspa?itemName=${itemName}&itemType=${itemType}&curpage=${i}">${i}</a></li>
                    </c:if>
                    <c:if test="${curs!=i}">
                        <li><a href="/admin/queryMenus2.jspa?itemName=${itemName}&itemType=${itemType}&curpage=${i}">${i}</a></li>
                    </c:if>
                </c:forEach>
                <c:if test="${curs>=pa}">
                    <li class="disabled"><a href="#">&raquo;</a></li>
                </c:if>
                <c:if test="${curs<pa}">
                    <li><a href="/admin/queryMenus2.jspa?itemName=${itemName}&itemType=${itemType}&curpage=${curs+1}">&raquo;</a></li>
                </c:if>
            </ul>
        </div>
       </c:if>
    </div>
</div>

<script>
    function fun(){
        window.location.href="/admin/queryMenuOrders.jspa?itemName="+$("#input1").val()+"&itemType="+$("#input2").val();
    }
//
    function goCancel2(ths){
        window.location.href="/admin/deleteMenu.jspa?menuId="+$(ths).prop("id");
    }
    function goCancel(ths){
            window.location.href="/admin//isUpDown.jspa?menuId="+$("#t1>tr:eq(0)").prop("id");
    }
    function goUping(ths){
        window.location.href="/admin/isUpDown2.jspa?menuId="+$("#t1>tr:eq(0)").prop("id");
    }
    function goEdit(ths){
            var ids = $(ths).parent().parent().prop("id");
            var names = $("#input1").val();
            var types = $("#sele1").val();
            var curs = $("#hid1").val();
            window.location.href="/admin/updateMenus.jspa?menuId="+ids+"&itemName="+names+"&itemType="+types+"&curpage="+curs;
    }
    function ups(tt){
        if($(tt).prop("checked")==true){
            $.ajax({
                type:"post",
                url:"${pageContext.request.contextPath}/admin/isUpDown2.jspa",
                data:"menuId="+$(tt).prop("id"),
                success:function(){
                }
            });
        }else{
            $.ajax({
                type:"post",
                url:"${pageContext.request.contextPath}/admin/isUpDown.jspa",
                data:"menuId="+$(tt).prop("id"),
                success:function(){
                }
            });
        }
    }
    $(function(){
        $("#bus").click(function(){
            window.location.href="/admin/menu/addMenu.jspa";
        });
    })
</script>
<script src="/statics/admin/js/My97DatePicker/WdatePicker.js"></script>